import course from 'api/course.js'
import { arrayCopy, swap } from 'utils'

export default {
	namespaced: true,

	state: {
		courses: [],
		examTypes: [
			{ key: 1, value: 'Practice', fn: 'getPraQues', submit: 'submitPra'},
			{ key: 2, value: 'Test', fn: 'getTestQues', submit: 'submitTest'},
			{ key: 3, value: 'Check', fn: 'getErrQues', submit: 'submitErr'},
		],
	},
	mutations: {
		courses({ courses }, newCourses) {
			arrayCopy(courses, newCourses.map(ele => {
				[ele.key, ele.value] = [ele.value, ele.key];
				return ele;
			}));
		},
	},
	actions: {
		getCourses({ commit }) {
			return course.getCourses()
							.done(data => {
								commit('courses', data);
			    			});
		},
		
		init({ dispatch }) {
			dispatch('getCourses');
		},
	}
}

